package com.enjoy.rocketmq;

import org.apache.rocketmq.client.log.ClientLogger;

import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.net.URL;
import java.util.Map;
import java.util.Objects;
import java.util.Properties;

public class Util {


    public static void loadProperties() throws IOException {

        System.out.println("File.pathSeparator = " + File.pathSeparator);
        System.out.println("File.pathSeparatorChar = " + File.pathSeparatorChar);

        System.out.println("File.separator = " + File.separator);
        System.out.println("File.separatorChar = " + File.separatorChar);

        URL url = Util.class.getClassLoader().getResource("");


        String path = Objects.requireNonNull(url).getPath() + "rocketmq.properties";

        Properties properties = new Properties();

        properties.load(new FileReader(path));

        for (Map.Entry<Object, Object> entry : properties.entrySet()) {
            if (entry.getKey().equals("nameserver.addr")) {
                System.setProperty(entry.getKey().toString(), entry.getValue().toString());
            }
        }
        System.setProperty(ClientLogger.CLIENT_LOG_USESLF4J, "true");

    }
}
